package com;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.connection.jdbconnection;

public class AdminStudentDelete extends HttpServlet {
	
	
	private static final long serialVersionUID = 1L;
	static Connection conn=null;
	PreparedStatement pst=null;
	Statement st=null;
	ResultSet rs=null;
	
	String sname=null;
	String fname=null;
	String dob=null;
	String gender=null;
	String address=null;
	String contact=null;
	String emailid=null;
	String course=null;
	String upload=null;
	String issuedate=null;
	String validuntile=null;
	


	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String student_id[] =request.getParameterValues("box");
	System.out.println(student_id);
		
		if(student_id !=null){
			try {
				jdbconnection db=new jdbconnection();
				st=db.jdbConnection();
				int b=0;
			for (int i = 0; i < student_id.length; i++) {
				
			
				String QString="Delete from studentform where student_id ='"+ student_id[i]+ "'";
				System.out.println(QString);
				
				b=st.executeUpdate(QString);
	
			}
		
			if(b>0)
			response.sendRedirect("AdminView.jsp");
				
			}catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
		}
		
		/* Only one record delete------------------------
		 
	if(student_id !=null){
		try {
			jdbconnection db=new jdbconnection();
			st=db.jdbConnection();
			
			String QString="Delete from studentform where student_id ='"+ student_id + "'";
			System.out.println(QString);
			
			st.executeUpdate(QString);
	}catch (Exception e) {
		// TODO: handle exception
		e.printStackTrace();
	}

	}  only one record delete.   */
	
	}

}